<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>修了个改</legend>
</fieldset>
<form class="layui-form" action="">
    <div class="layui-form-item" hidden>
        <div class="layui-inline">
            <label class="layui-form-label">联系方式</label>
            <div class="layui-input-inline">
                <input type="tel" name="id" class="layui-input" value="${student.id}">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="name" autocomplete="off" class="layui-input"
                       value="${student.name!}">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-inline">
                <input type="number" name="age" lay-verify="required|number" autocomplete="off" class="layui-input"
                       value="${student.age!}">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">年级</label>
            <div class="layui-input-inline">
                <input type="text" name="grade" lay-verify="required" autocomplete="off"
                       class="layui-input" value="${student.grade!}">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">分数</label>
            <div class="layui-input-inline">
                <input type="number" name="score" lay-verify="required|number" autocomplete="off" class="layui-input"
                       value="${student.score!}">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">联系方式</label>
            <div class="layui-input-inline">
                <input type="tel" name="mobile" lay-verify="required|phone" autocomplete="off"
                       class="layui-input" value="${student.mobile!}">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">单选框</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="${student.gender!}" title="男" checked="">
            <input type="radio" name="sex" value="${student.gender!}" title="女">
            <input type="radio" name="sex" value="禁" title="禁用" disabled="">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>


<script src="/static/layui/layui.all.js" charset="utf-8"></script>
<script src="/static/jquery.min.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('element', function(){
        var element = layui.element;

    });
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        //自定义验证规则
        form.verify({
            name: function (value) {
                if (value.length < 2) {
                    return '名字至少得2个字吧';
                }
            }
        });
        //监听提交
        form.on('submit(demo1)', function (data) {
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // })
            var params = data.field;
            submit(params);
            return false;
        });
    });

    function submit(params) {
        $.ajax({
            url: "/student/edit",
            method: 'post',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(params),
            success: function (res) {
                if (res) {
                    alert(res.code);
                    // alert("添加成功！");
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                    parent.location.reload(); // 父页面刷新
                }
            }
        });
    };

    //关闭页面
    function CloseWin(res) {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
        parent.$("#handle_status").val(res.code);
        parent.location.reload(); // 父页面刷新
    };
</script>

</body>
</html>